package com.wsl.Email;

import com.wsl.StatusContent;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

/**
 * @Author: wsl
 * @Date: 2022/4/1 13:51
 */
public class EmailUtils {


    public static void sendEmail(String email,String code){
        try {
            //String aa = "1030947980@qq.com";
            //String aa = "15036787751@163.com";
            HtmlEmail he = new HtmlEmail();
            //邮箱的SMTP服务器
            he.setHostName("smtp.163.com");
            //设置发送的字符类型
            he.setCharset("utf-8");
            //设置收件人
            he.addTo(email);
            // SSL安全连接
            he.setSSLOnConnect(true);
            //发送人
            he.setFrom(StatusContent.EMAIL_USERNAME);
            //设置发送人到的邮箱和用户名和授权码(授权码是自己设置的)
            he.setAuthentication(StatusContent.EMAIL_USERNAME,StatusContent.EMAIL_CODE);
            he.setSubject("测试邮箱发送");//设置发送主题
            he.setMsg(StatusContent.EMAIL_CONTENT+" "+code);//设置发送内容
            he.send();//进行发送
        } catch (EmailException e) {
            e.printStackTrace();
        }
    }


}